package ui.component
{

	import flash.display.BitmapData;
	import flash.text.TextFormatAlign;

	import util.TextStyle;

	public class TextButton extends Button
	{
		private var _label:Label;
		private var _offsetX:Number = 0; //文字偏移量
		private var _offsetY:Number = 0;

		public function TextButton(text:String, defaultData:BitmapData, overData:BitmapData = null, downData:BitmapData = null, disableData:BitmapData = null,
			handler:Function = null)
		{
			super(defaultData, overData, downData, disableData, handler);

			_label = new Label(12, 0xFFFFFF, false, TextFormatAlign.LEFT);
			this.text = text;
			this.addChild(_label);
		}

		public function set text(value:String):void
		{
			if(value != '' && value != null)
			{
				getLabel().text = value;
				_label.x = (width == 0) ? 0 : (width - _label.width) * 0.5 + _offsetX;
				_label.y = (height == 0) ? 0 : (height - _label.height) * 0.5 + _offsetY;
			}
		}

		public function getLabel():Label
		{
			return _label;
		}

		public function set offsetY(value:Number):void
		{
			_offsetY = value;
			_label.y = (height - _label.height) * 0.5 + _offsetY;
		}

		public function set offsetX(value:Number):void
		{
			_offsetX = value;
			_label.x = (width - _label.width) * 0.5 + _offsetX;
		}

		/**是否有边框**/
		public function set isBorderColor(value:Boolean):void
		{
			_label.filters = value ? [TextStyle.getButtonTextFilter()] : [];
		}
	}
}